package org.forum.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="main_topic")
public class MainTopic {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(nullable=false)
	private int mainTopicId;
	
	@Column(nullable=false)
	private int publisherId;
	
	private String title;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false)
	private Date addTime;
	
	//mark whether it is a announcement
	@Column(nullable=false)
	private boolean isAnnouncement;
	
	private String essay;
	
	@ManyToOne(targetEntity=User.class)
	@JoinColumn(name="userId",referencedColumnName="userId", nullable=false)
	private User user;
	
	@OneToMany(targetEntity=ViceTopic.class,mappedBy="mainTopic")
	private Set<ViceTopic> viceTopics = new HashSet<>();
	
	@OneToMany(targetEntity=Picture.class)
	@JoinColumn(name="mainTopicId", referencedColumnName="mainTopicId")
	private Set<Picture> pictures= new HashSet<>();
	
	public int getMainTopicId() {
		return mainTopicId;
	}

	public void setMainTopicId(int mainTopicId) {
		this.mainTopicId = mainTopicId;
	}

	public int getPublisherId() {
		return publisherId;
	}

	public void setPublisherId(int publisherId) {
		this.publisherId = publisherId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Date getAddTime() {
		return addTime;
	}

	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}

	public boolean isAnnouncement() {
		return isAnnouncement;
	}

	public void setAnnouncement(boolean isAnnouncement) {
		this.isAnnouncement = isAnnouncement;
	}

	public String getEssay() {
		return essay;
	}

	public void setEssay(String essay) {
		this.essay = essay;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Set<ViceTopic> getViceTopics() {
		return viceTopics;
	}

	public void setViceTopics(Set<ViceTopic> viceTopics) {
		this.viceTopics = viceTopics;
	}

	public Set<Picture> getPictures() {
		return pictures;
	}

	public void setPictures(Set<Picture> pictures) {
		this.pictures = pictures;
	}
	
	
}
